package tree.leetcode_958_medium;

import java.util.LinkedList;
import java.util.Queue;

public class BestIsCompleteTree {
    public boolean isCompleteTree(TreeNode root) {
        if(root == null){
            return true;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        TreeNode pre = root;
        queue.add(root);
        while(!queue.isEmpty()){
            TreeNode node = queue.poll();
            if(node != null){
                queue.add(node.left);
                queue.add(node.right);
            }
            if(pre == null && node != null){
                return false;
            }
            pre = node;
        }
        return true;
    }
}
